﻿using System;
using System.Collections.Generic;
using System.Text;

using Bpms.Data;
using Bpms.Log;
using Bpms.Entity;
using Bpms.OrderStrategy;
using Bpms.Config;
using Bpms.Log;

namespace Bpms.Bll
{

    /// <remarks>
    /// 数据库改变，需要重新缓存数据，使用该委托代理的方法使缓存失效。
    /// </remarks>
    public delegate void DBChangedEventHandler();

    /// <summary>
    /// 使用该委托代理的方法进行日志操作。
    /// </summary>
    public delegate void LogEventHandler(string s);


    public class Order
    {
        // private LogAdapter log;
        private static IOrderStrategy orderStrategy;
        public static event DBChangedEventHandler DBChanged;
        public static event LogEventHandler WriteLog;

        static Order()
        {
            // DBChanged += new DBChangedEventHandler(RemoveCache);
            //   WriteLog += new LogEventHandler(WriteLog());
        }

        //  private static void RemoveCache() { }
        // private static void WriteLog(string message) { }

        public static void SetOrderStrategy(IOrderStrategy stategy)
        {
            orderStrategy = stategy;
        }

        public static string GetInfo(int orderId)
        {
            if (orderId < 1)
            {
                return null;
            }

            //   return orderStrategy.GetOrder(orderId);
            return "";
        }

        public static string GetOrders(int pageId, int pageSize, string condition)
        {
            return "";
        }

        public static bool AddOrder(OrderInfo order, string msg)
        {
            DBChanged();

            WriteLog(msg);
            return true;

        }

        public static bool UpdateOrder(OrderInfo order, string msg)
        {
            DBChanged();
            WriteLog(msg);
            return true;

        }


        public static Type GetType(string className)
        {
            if (!string.IsNullOrEmpty(className))
            {
                Activator.CreateInstance(Type.GetType(string.Format("Bpms.Data.{0}.{1}, Data.{0}", ConfigContext.GetDbType, className), true, true));
                //return Type.GetType(string.Format("Bpms.Data.{0}.{1}, Data.{0}", ConfigContext.GetDbType, className), true, true);
            }



            IDataProvider provider = DatabaseProvider.GetInstance();

            provider.CancelPo(1);

            // provider.SetLog(new OperationLogAdapter());
            //  provider.InsertArea();


            return null;

        }
    }
}
